/*
 *
 * Created on: 22.09.2012
 *
 * exception.cpp
 * This file is part of KOBUS
 * 
 * Copyright (C) 2012 - Ivan Penkin, MIPT
 * grek.penkin@gmail.com
 *
 * KOBUS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KOBUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KOBUS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 *  
 */

#include <exception.h>

#include <errno.h>

using namespace kobus;


Exception::Exception(const int errcode, QObject * parent)
    :QObject(parent),
    d_errno(errcode),
    d_message(strerror( d_errno )) {

  log();
};


Exception::Exception(
                  const int errcode,
                  const QString & messge,
                  QObject * parent)
    :QObject(parent),
    d_errno(errcode),
    d_message(messge) {

  log();
};


Exception::Exception(const Exception & rhs)
    :QObject(rhs.parent()) {

  setErrcode(rhs.errcode());
  setMessage(rhs.message());
}


Exception::Exception(Exception & rhs)
    :QObject(rhs.parent()) {

  setErrcode(rhs.errcode());
  setMessage(rhs.message());
}


Exception & Exception::operator=(const Exception & rhs) {

  setErrcode(rhs.errcode());
  setMessage(rhs.message());
  return * this;
}


int Exception::errcode() const {

  return d_errno;
};


void Exception::setErrcode(const int err) {

  d_errno = err;
};


const QString & Exception::message() const {

  return d_message;
};


void Exception::setMessage(const QString & message) {

  d_message = message;
};


void Exception::log() const {

  d_log.write(
           Log::LOG_ERR, "Exception: %s",
           d_message.toLocal8Bit().constData());
}

